#include "FrameAnimate.h"

FrameAnimate::FrameAnimate(void)
{
}


FrameAnimate::~FrameAnimate(void)
{
}

void FrameAnimate::init(std::string name,long fMax,long delay,bool loop)
{
	initTexture(name);
	_frameSize = getImageSize();
	_frameSize.x /= fMax;
	setImageSize(_frameSize);

	_frameDelay = delay;
	_isLoop = loop;
	_frameTime = 0;
	_frameNum = 0;
	_frameMaxNum = fMax;
}

void FrameAnimate::draw()
{
	_frameTime++;
	if( _frameTime >= _frameDelay )
	{
		_frameNum++;
		_frameTime = 0;
		if( _frameNum >= _frameMaxNum )
		{
			if( _isLoop ) _frameNum = 0;
			else _frameNum = _frameMaxNum;
		}
		setDrawPoint(Vector3l(_frameSize.x*_frameNum, 0));
	}

	GameObject::draw();
}

bool FrameAnimate::isEndAnimate()
{
	return (_isLoop || (_frameNum == _frameMaxNum));
}
